package com.mz.ozy.mvp.presenter;


import android.app.Activity;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.StorageInfoBean;
import com.mz.ozy.mvp.model.StorageModel;
import com.mz.ozy.mvp.view.StorageContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class StoragePresenter extends BasePresenterImpl<StorageContract.View> implements StorageContract.Presenter {

    private StorageModel mModel;

    public StoragePresenter() {
        mModel = new StorageModel();
    }

    @Override
    public void getStorageInfo(Activity activity) {
        mModel.getStorageInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<StorageInfoBean>(mView) {
                    @Override
                    public void onSuccesss(StorageInfoBean bean) {
                        mView.getStorageInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void confirmStore(Activity activity, String amt, String password) {
        mModel.confirmStore(activity, amt, password)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.confirmStoreSuccess(bean);
                    }
                });
    }
}
